<template>
  <a-card :bordered="false">
    <!-- 查询区域 员工绩效表--【城市】 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="月份">
              <j-date placeholder="请选择月份" v-model="queryParam.month"
                      style="width:100%"
                      dateType="month"
                      :show-time="false"
                      date-format="YYYY-MM"></j-date>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="部门">
<!--              <j-org-city-linkage v-model="queryParam.orgCode" type="select"></j-org-city-linkage>-->
              <!-- <j-input placeholder="请输入部门" type="" v-model="queryParam.orgCode"></j-input> -->

              <a-select placeholder="请选择部门" v-model="queryParam.teamId" allowClear @change="changeTeam">
                <a-select-option v-for="(item, i) in teamData" :key="i" :value="item.id">
                  {{ item.label }}
                </a-select-option>
              </a-select>

            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="城市">
              <!-- <j-input placeholder="请输入城市" type="" v-model="queryParam.cityName"></j-input> -->

              <a-select placeholder="请选择城市" v-model="queryParam.cityId" allowClear>
                <a-select-option v-for="(item, i) in cityData" :key="i" :value="item.deptId">
                  {{ item.label }}
                </a-select-option>
              </a-select>

            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('员工绩效表--【城市】')">导出</a-button>
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
    </div>

    <!-- table区域-begin -->
    <div>


      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"

        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="cityName" slot-scope="text, row">
          <a-button v-if="text" type="link" @click="$router.push({ path: '/emp/EmpIncomeList', query: row })">{{ text }}</a-button>
        </template>
      </a-table>
    </div>

    <emp-income-modal ref="modalForm" @ok="modalFormOk"></emp-income-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import EmpIncomeModal from './modules/EmpIncomeModal'
  import {JVXETypes} from "@comp/jeecg/JVxeTable";
  import {getAction} from "@api/manage";

  export default {
    name: 'EmpIncomeCityList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      EmpIncomeModal
    },
    data () {
      return {

        teamData: [],
        cityData: [],

        description: '收支月度报表管理页面',


        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'月份',
            align:"center",
            dataIndex: 'month'
          },
          {
              title:'团队',
              align:"center",
              dataIndex: 'teamName'
          },
          {
              title:'城市',
              align:"center",
              dataIndex: 'cityName',
              scopedSlots: { customRender: 'cityName' }
          },

          {
            title:'薪资合计',
            align:"center",
            dataIndex: 'salary'
          },
          {
            title:'营销费用',
            align:"center",
            dataIndex: 'market'
          },
          {
            title:'人工上报营销费用',
            align:"center",
            dataIndex: 'marketManual'
          },
          {
            title:'办公场地(均摊)',
            align:"center",
            dataIndex: 'officeSpace'
          },
          {
            title:'办公家具(均摊)',
            align:"center",
            dataIndex: 'officeFurniture'
          },
          {
            title:'其他',
            align:"center",
            dataIndex: 'other'
          },
          {
            title:'总支出',
            align:"center",
            dataIndex: 'totalPay'
          },
          {
            title:'总收入',
            align:"center",
            dataIndex: 'totalIncome'
          }
        ],
        url: {
          list: "/emp/empIncome/queryEmpIncomePageByCity",
          delete: "/emp/empIncome/delete",
          deleteBatch: "/emp/empIncome/deleteBatch",
          exportXlsUrl: "/emp/empIncome/exportListByCity",
          importExcelUrl: "emp/empIncome/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getTeamList() // 获取团队列表
      if (this.$route.query.month) {
        this.queryParam = {
          month: this.$route.query.month || '',
          teamId: Number(this.$route.query.teamId) || '',
          cityId: Number(this.$route.query.cityId) || ''
        }
        !this.queryParam.cityId && delete this.queryParam.cityId
        this.searchQuery()
        if (this.queryParam.teamId) {
          setTimeout(() => {
            this.teamData.some(row => {
              if (row.id === this.queryParam.teamId) {
                this.cityData = row.children || []
                return true
              }
            })
          }, 500)
        }
      } else {
        this.getSuperFieldList()
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      // 改变团队
      changeTeam(val, opt) {
        this.cityData = this.teamData[opt.key].children || []
        delete this.queryParam.cityId
      },
      // 获取团队列表
      getTeamList() {
        getAction("/emp/emp_58Pay/queryRpDeptTree", {}).then((res) => {
          this.teamData = res.result || []
        })
      },

      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'cityName',text:'所在城市',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'salary',text:'薪资',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'market',text:'营销费用',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'marketManual',text:'人工上报营销费用',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'officeSpace',text:'办公场地(均摊)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'officeFurniture',text:'办公家具(均摊)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'other',text:'其他',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'totalPay',text:'总支出',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'totalIncome',text:'总收入',dictCode:''})

        this.superFieldList = fieldList
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>